#######################
# Table 2
# This uses WTGN's original data, Our data
# Creates Table 2, providing n and percentage passing and failing manipulation checks
#######################

#Get weighted measure of those failing check from Survey
R1<-svytable(~CORRECT,nd)

#Get measure of those failing check from WTGN's first survey
WTGN1<-xtabs(~passed01,study1)

#Get measure of those failing check from WTGN's second survey
WTGN2<-xtabs(~passed01,study2)

#Get measure of those failing check from WTGN's third survey
WTGN3<-wtd.table(study3$passed01,weights=study3$weight)$sum.of.weights

#bind these together as dataframe
T2<-as.data.frame(rbind(R1,WTGN1,WTGN2,WTGN3))

#re-title column names to be more descriptive
colnames(T2)<-c("Failed","Passed")

#round to whole numbers for all values
T2<-round(T2)

#add total n for each survey
T2$Total<-rowSums(T2)

#compute those failing/passing manipulation checks as a percentage
T2$Percent_Failed<-round((T2$Failed/T2$Total)*100,1)
T2$Percent_Passed<-round((T2$Passed/T2$Total)*100,1)

#write out results
write.csv(T2,"../Main Results/T2.csv",row.names=TRUE)

